
function formSubmit(obj){
	
	var content=$(obj);
	content.parents("form").submit();
}

function initPage(dataInfo){
	var basePath = $("#basePath").val();
	$("select:not([data-address])").each(function(){
		$(this).append("<option value=''>---请选择---</option>");
		
	});
	
	$("select[data-type='129Select']").each(function(){
		var options = "";
		options+="<option value='1'>是</option>";
		options+="<option value='2'>否</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select[data-type='infectionCell']").each(function(){
		var options = "";
		
		options+="<option value='1'>耐甲氧西林的金黄色葡萄球菌</option>";
		options+="<option value='2'>耐万古霉素的粪肠球菌</option>";
		options+="<option value='3'>耐万古霉素的屎肠球菌</option>";
		options+="<option value='4'>耐碳青霉烯类的大肠埃希菌</option>";
		options+="<option value='5'>耐碳青霉烯类的肺炎克雷伯菌</option>";
		options+="<option value='6'>耐碳青霉烯类的鲍曼不动杆菌</option>";
		options+="<option value='7'>耐碳青霉烯类的铜绿假单胞菌</option>";
		options+="<option value='8'>耐甲氧西林金黄色葡萄球菌（MRSA)</option>";
		options+="<option value='9'>耐万古霉素肠球菌（VRE）</option>";
		options+="<option value='10'>耐碳青霉烯类肠杆菌（CRE)</option>";
		options+="<option value='11'>多重耐药鲍曼不动杆菌（MDR Ab)</option>";
		options+="<option value='12'>多重耐药铜绿假单胞杆菌（MRPA)</option>";
		options+="<option value='13'>其他</option>";
		
		$(this).append(options);
	});
	
	$("select[data-type='infectionPart']").each(function(){
		var options = "";
		options+="<option value='1'>呼吸道</option>";
		options+="<option value='2'>泌尿系统</option>";
		options+="<option value='3'>血流</option>";
		options+="<option value='4'>手术部位</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	$("select[data-type='infectionTime']").each(function(){
		var options = "";
		options+="<option value='1'>1次</option>";
		options+="<option value='2'>2次</option>";
		options+="<option value='3'>3次</option>";
		options+="<option value='4'>4次及4次以上</option>";
		$(this).append(options);
	});
	$("select[data-type='curativeEffect']").each(function(){
		var options = "";
		options+="<option value='1'>治愈</option>";
		options+="<option value='2'>好转</option>";
		options+="<option value='3'>未愈</option>";
		options+="<option value='4'>死亡</option>";
		options+="<option value='9'>-</option>";
		$(this).append(options);
	});
	
	$("select").each(function(){
		$(this).change(function(){
	   		var eventObj = $(this);
	   		var nameObjName = eventObj.attr("name").replace("Code", "Name");
	   		
	   		if(eventObj.val()!=""){
	   			var name=eventObj.find("option:selected").text();
	   			eventObj.next("input[name='"+nameObjName+"']").val(name);
	   		}else{
	   			eventObj.next("input[name='"+nameObjName+"']").val("");
	   		}
	   });
	});
	
	$("input[type='radio']").each(function(){
		$(this).click(function(){
			 $(this).nextAll("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val($(this).attr("title"));
		});
		$(this).dblclick(function(){
			$(this).removeAttr("checked");
			$(this).nextAll("input[name='"+$(this).attr("name").replace("Code", "Name")+"']").val(null);
		});
	});
	
	if(dataInfo){
		radioValue("whetherHospitalInfectionCode",dataInfo.whetherHospitalInfectionCode,
				"whetherHospitalInfectionName",dataInfo.whetherHospitalInfectionName);
		
		$("input[name='infectionCellName']").val(dataInfo.infectionCellName);
		/*selectValue("infectionCellCode",dataInfo.infectionCellCode,
				"infectionCellName",dataInfo.infectionCellName);*/
		
		selectValue("infectionPartCode",dataInfo.infectionPartCode,
				"infectionPartName",dataInfo.infectionPartName);
		
		/*selectValue("infectionTimeCode",dataInfo.infectionTimeCode,
				"infectionTimeName",dataInfo.infectionTimeName);*/
		$("input[name='infectionTime']").val(dataInfo.infectionTime);
		selectValue("curativeEffectCode",dataInfo.curativeEffectCode,
				"curativeEffectName",dataInfo.curativeEffectName);
	}
	/*initProeesureSores(dataInfo);
	initFallDown(dataInfo);
	initPhysicalConstraint(dataInfo);
	initObstetricDelivery(dataInfo);*/
	var validator = $("#hospitalSurveyInfectionInfoForm").validate({
		errorElement: "title",
		ignoreTitle: true,
		submitHandler : function(){
			layer.load(1);
			return true;
		},
		rules:{
			'infectionTime': {
				digits:true,
            	range:[1,1000]
            }
			
		},
		
	});
}

function selectValue(codeName,codeValue,nameName,nameValue){
	if(codeValue){
	  	var selectedIndex = $("select[name='"+codeName+"'] option[value='"+codeValue+"']").first().index();
		if (selectedIndex == -1) {
			var option = "<option selected value='" + codeValue + "'>" + nameValue + "</option>";
			$("select[name='"+codeName+"']").append(option);
		} else {
			$("select[name='"+codeName+"']").get(0).selectedIndex = selectedIndex;
		}
	}
	$("select[name='"+codeName+"']").next("input[name='"+nameName+"']").val(nameValue);
}

function radioValue(codeName,codeValue,nameName,nameValue){
	if(codeValue){
		$("input[name='"+codeName+"'][value='"+codeValue+"']").attr("checked",true);
	}
	$("input[name='"+nameName+"']").val(nameValue);
}